package com.bz.content.service.impl;

import com.bz.content.feign.CommonContentFeignClient;
import com.bz.content.service.ContentCategoryService;
import com.bz.pojo.TbContentCategory;
import com.bz.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ContentCategoryServiceImpl implements ContentCategoryService {

    @Autowired
    private CommonContentFeignClient commonContentFeignClient;

    /**
     * 根据父节点ID查询子节点
     * @param parentId
     * @return
     */
    @Override
    public Result selectContentCategoryByParentId(Long parentId) {
        return Result.ok(commonContentFeignClient.selectContentCategoryByParentId(parentId));
    }

    /**
     * 添加内容分类
     * @param tbContentCategory
     * @return
     */
    @Override
    public Result insertContentCategory(TbContentCategory tbContentCategory) {
        Integer result = commonContentFeignClient.insertContentCategory(tbContentCategory);
        if (result != null){
            return Result.ok();
        }
        return Result.error("操作失败");
    }

    /**
     * 删除内容分类
     * @param id
     * @return
     */
    @Override
    public Result deleteContentCategoryById(Long id) {
        TbContentCategory tbContentCategory = new TbContentCategory();
        tbContentCategory.setStatus(2);
        Integer result = commonContentFeignClient.deleteContentCategoryById(tbContentCategory);
        if (result != null && result == 200){
            return Result.ok();
        }
        return Result.error("操作失败");
    }

    /**
     * 修改内容分类名称
     * @param tbContentCategory
     * @return
     */
    @Override
    public Result updateContentCategory(TbContentCategory tbContentCategory) {
        Integer result = commonContentFeignClient.updateContentCategory(tbContentCategory);
        if (result != null){
            return Result.ok();
        }
        return Result.error("操作失败");
    }
}
